<template>
    <div class="phoneKey">
        <!-- 顶部状态栏 -->
        <div class="top">
            <van-icon name="arrow-left" size="20px" @click="goback()" />
            <div>个人信息</div>
        </div>
        <!-- <div class="imgs">
            <img src="../assets/img/img2/rentou.jpg" alt="">
            <img src="../assets/img/img2/rentou.jpg" alt="">
        </div> -->
        <div class="duan">
            <van-cell-group>
                <van-field v-model="username" label-width="50%" label="姓名:" readonly />
            </van-cell-group>
            <van-cell-group>
                <van-field v-model="sex" label-width="50%" label="性别:" readonly />
            </van-cell-group>
            <van-cell-group>
                <van-field v-model="birthday" label-width="50%" label="出生日期:" readonly />
            </van-cell-group>
            <van-cell-group>
                <van-field v-model="type" label-width="50%" label="民族:" readonly />
            </van-cell-group>
        </div>
        <van-cell-group>
                <van-field v-model="idCard" label-width="90px" label="身份证号:" readonly />
            </van-cell-group>
            
                <van-cell-group>
                        <van-field v-model="commit" label-width="90px" label="小区名称:" readonly />
                    </van-cell-group>
                    <van-cell-group>
                            <van-field v-model="inforAddress" label-width="90px" label="楼栋单元:" readonly />
                        </van-cell-group>
                        <van-cell-group>
                                <van-field v-model="address" label-width="90px" label="家庭住址:" readonly />
                            </van-cell-group>
                            <van-cell-group>
                                    <van-field v-model="master_info" label-width="90px" label="户主关系:" readonly />
                                </van-cell-group>
    </div>
</template>

<script>
    import { mapState, mapMutations } from 'vuex'
    import { Step, Steps } from 'vant'
    import { Icon ,Toast} from 'vant'
    export default {
        // 当前组件的名称
        name: 'home',

        data() {
            return {
                active: 1,
                username: "张三",
                sex: "女",
                birthday:"1997-01-07",
                type:"汉",
                idCard:"421222199602022828",
                address:"湖北省武汉市光谷一路佛祖岭",
                commit:"",
                master_info:"",
                inforAddress:""

            }
        },

        // 在当前组件中添加其他的自定义组件
        components: {

        },

        /*
            在computed中添加mapState
            如果computed中只有一个辅助函数，后面可以直接写成函数名
        */
        computed: {
            ...mapState(['token', 'userid', "userPhone"]), // this.token相当于this.$store.state.token

        },
        methods: {
            ...mapMutations(['changeToken', "changehomeId"]),

            goback() {
                this.$router.back()
            },
            // 获取用户信息
            getCommunityList() {
                let that = this
                this.$axios.get('/comm/getuserCardComm', {
                    params: {
                        user_id: this.userid
                    }
                }).then((res) => {
                    //console.log(res);
                    let { message, data, status } = res;
                    console.log(res)
                    if (status == 200 && data.code==200) {
                       this.username=data.data.name;
                       this.sex=data.data.sex;
                       this.type=data.data.nation;
                       this.idCard=data.data.id_card_num
                       this.birthday=data.data.birthday
                       this.address=data.data.adds
                       const {comm_name,buil_name,unit_name,room_name,master_info}=data.data.commlist[0]
                       this.commit=comm_name
                       this.inforAddress=comm_name+buil_name+unit_name+room_name+"室"
                       this.master_info=master_info
                    }
                })
            },
           

        },
        // 生命周期函数,创建实例,可以获取this,但DOM节点还没有创建出来
        created() {
            console.log('created', this.$el)
            this.getCommunityList()
            
        },
        // 生命周期函数,当前组件上的所有DOM节点都已经创建出来
        mounted() {
            

            // 监听页面滚动,显示返回顶部的图标
            // window.onscroll = this.onScroll

            // 请求获取轮播图
            //this.reqSwiperItems()
            // 请求获取商品列表的第一页
            //this.reqGoodsList()

            // 获取存在本地的token
            // const token = localStorage.getItem('token')
            // 把token存到当前组件的data中
            // this.token = token

            // 从store中获取最新的token
            // this.token = this.$store.state.token

            // console.group('-----------睁大你的狗眼-----------')
            // console.log('home里面的token为',this.token)
            // console.groupEnd()
        },
        // 生命周期函数,当数据发生改变并且导致视图发生相应的改变
        updated() {
            // console.log('updated')
        },
        // 生命周期函数,组件被销毁
        destroyed() {
            console.log('destroyed')
        },
        // 生命周期函数,进入缓存组件
        activated() {
            console.log('activated')
            this.getExamine()
            this.username = this.userPhone
            // 再次回来的时候,直接滚动到之前离开时候保存的位置


            // 如果每次进入缓存组件的时候，需要实时更新当前组件中的内容，可以将这些更新代码写在activated

            // 请求获取用户信息
            // this.reqUserInfo()
            // this.$store.dispatch('changeUserInfo2')

        },
        // 生命周期函数,离开缓存组件
        deactivated() {
            console.log('deactivated')

            // 不要尝试去获取页面的scrollTop,因为页面只有一个,跳转到新的路由,页面的scrollTop会变成0
            // 所以,在离开的时候,把当前组件的scrollTop保存下来,赋给一个新的变量
            // this.cache_scrollTop = this.scrollTop
        },
        // 离开路由之前,它会在deactivated之前调用
        beforeRouteLeave(to, from, next) {
            console.log('beforeRouteLeave')

            // 1.获取页面的scrollTop,赋给一个新的变量
            // this.cache_scrollTop = document.documentElement.scrollTop || document.body.scrollTop

            // 2.获取顶部状态栏距离父元素底部的距离,赋给一个新的变量


            // 必须调用next,否则就不会离开当前路由
            next()
        }
    }
</script>

<!-- 添加scoped属性,将样式的作用域限制在当前组件内,不会影响子组件 -->
<style lang="scss" scoped>
    .top {

        height: 40px;
        line-height: 40px;
        position: relative;
        font-size: 16px;
        border-bottom: 1px solid #999;
        margin-bottom: .3rem;
    }

    .top div {
        text-align: center;

    }

    .van-icon-arrow-left {
        position: absolute;
        top: 10px;
    }

    .imgs {
        display: flex;
        justify-content: space-around;

        img {
            width: 48%;
            height: auto;
        }
    }
    .duan{
        display: flex;
        justify-content: space-around;
        flex-wrap: wrap;
        .van-cell-group{
            width: 48%;
            
        }
        
    }
    
</style>